package com.youease.chris.control
{
	import com.youease.chris.manager.GlobalObject;
	import com.youease.chris.model.proxy.MapDataProxy;
	import com.youease.chris.view.mediator.MapEditMediator;
	import com.youease.chris.view.mediator.MapPropertiesMediator;
	import com.youease.chris.view.mediator.MapSceneMediator;
	
	import org.puremvc.as3.interfaces.ICommand;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	public class CreateMapCommand extends SimpleCommand implements ICommand
	{
		public static const CREATE_MAP:String = "create_map";
		public static const MAP_NAME_NULL:String = "map_name_null";
		public static const CREATE_MAP_COMPLETE:String = "create_map_complete";
		
		public function CreateMapCommand()
		{
			super();
		}
		
		override public function execute(notification:INotification):void {
			var mapDataProxy:MapDataProxy = notification.getBody() as MapDataProxy;
			
			if(!this.facade.hasMediator(MapSceneMediator.NAME))
				this.facade.registerMediator(new MapSceneMediator((this.facade.retrieveMediator(MapEditMediator.NAME) as MapEditMediator).mapEdit.mapScene));
			if(!this.facade.hasMediator(MapPropertiesMediator.NAME))
				this.facade.registerMediator(new MapPropertiesMediator((this.facade.retrieveMediator(MapEditMediator.NAME) as MapEditMediator).mapEdit.mapProperties));
			if(!this.facade.hasCommand(MapSceneCommand.CREATE_SCENE))
				this.facade.registerCommand(MapSceneCommand.CREATE_SCENE,MapSceneCommand);
			if(!this.facade.hasCommand(RandomMapCommand.RANDOM_MAP))
				this.facade.registerCommand(RandomMapCommand.RANDOM_MAP,RandomMapCommand);
			sendNotification(CREATE_MAP_COMPLETE,mapDataProxy);
			sendNotification(MapSceneCommand.CREATE_SCENE,mapDataProxy);
			GlobalObject.currentMap = mapDataProxy.mapData.name;
		}
	}
}